import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import GoodsView from "@/views/userView/GoodsView.vue";
import HomeView from "@/views/userView/HomeView.vue";
import GroupView from "@/views/userView/GroupView.vue";
import UserOrder from "@/views/userView/UserOrder.vue";
import UserLogin from "@/views/userView/UserLogin.vue";
import UserRegister from "@/views/userView/UserRegister.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    component: HomeView
  },
  {
    path: "/user",
    name: "user",
    children: [
      {
        path: "home",
        name: "userHome",
        component: HomeView,
      },
      {
        path: "help",
        name: "helpFarmer",
        component: () => import("@/views/help/HelpView.vue"),
      },
      {
        path: "goods",
        name: "userGoods",
        component: GoodsView,
      },
      {
        path: "group",
        name: "userGroup",
        component: GroupView,
      },
      {
        path: "Login",
        name: "userLogin",
        component: UserLogin,
      },
      {
        path: "settings",
        name: "userSettings",
        component: () => import("@/views/userView/UserSettings.vue")
      },
      {
        path: "goods/detail/:id",
        name: "goodsDetail",
        component: () => import("@/views/goods/GoodsView.vue"),
      },
      {
        path: "allOrder",
        name: "userAllOrder",
        component: () => import("@/views/userView/UserAllOrder.vue")
      },
      {
        path: "orderDetail",
        name: "userOrderDetail",
        component: UserOrder,
      },
      {
        path: "register",
        name: "userRegister",
        component: UserRegister,
      },
    ]
  },
  {
    path: "/seller",
    name: "sellerView",
    children: [
      // 子路由路径不要以 / 开头
      {
        path: "goods", // 完整路径会自动拼接为 /seller/goods
        name: "sellerGoods",
        children: [
          {
            path: "list",
            name: "sellerGoodsList",
            component: () => import("@/views/sellerView/goods/SellerGoods.vue")
          },
          {
            path: "unPublish",
            name: "sellerGoodsUnPublish",
            component: () => import("@/views/sellerView/goods/unPublish.vue")
          },
          {
            path: "waitReview",
            name: "sellerGoodsWaitReview",
            component: () => import("@/views/sellerView/goods/waitReview.vue")
          },
          {
            path: "add",
            name: "addNewGoods",
            component: () => import("@/views/sellerView/goods/addNewGoods.vue")
          }
        ]
      },
      {
        path: "order",
        name: "sellerOrder",
        children: [
          {
            path: "list",
            name: "sellerOrderList",
            component: () => import("@/views/sellerView/order/SellerOrderView.vue")
          },
          {
            path: "group",
            name: "groupOrder",
            component: () => import("@/views/sellerView/order/SellerGroupOrder.vue")
          }
        ]
      },
      {
        path: "group",
        name: "sellerGroup",
        children: [
          {
            path: "list",
            name: "sellerGroupList",
            component: () => import("@/views/sellerView/group/SellerGroup.vue")
          }
        ]
      }
    ],
  },
  {
    path: "/admin",
    name: "adminView",
    children: [
      {
        path: "goods",
        name: "goods",
        children: [
          {
            path: "list",
            name: "goodsList",
            component: () => import("@/views/adminView/goods/GoodsView.vue"),
          },
          {
            path: "publish",
            name: "goodsPublish",
            component: () => import("@/views/adminView/goods/GoodsPublish.vue")
          }
        ]
      },
      {
        path: "order",
        name: "order",
        children: [
          {
            path: "list",
            name: "orderList",
            component: () => import("@/views/adminView/order/OrderView.vue"),
          },
        ]
      },
      {
        path: "users",
        name: "users",
        children: [
          {
            path: "account",
            name: "userAccount",
            component: () => import("@/views/adminView/users/UsersAccount.vue")
          }
        ]
      },
      {
        path:"seller",
        name: "seller",
        children: [
          {
            path: "register",
            name: "sellerRegister",
            component: () => import("@/views/adminView/seller/SellerRegister.vue")
          },
          {
            path: "account",
            name: "sellerAccount",
            component: () => import("@/views/adminView/seller/SellerAccount.vue"),
          },
          {
            path: "publish",
            name: "sellerPublish",
            component: () => import("@/views/adminView/seller/SellerPublish.vue"),
          },
        ]
      }
    ],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
